package cn.psvmc.cxzapi.controller.customer;

import cn.psvmc.cxzapi.constant.GlobalConstant;
import cn.psvmc.cxzapi.model.customer.TCustomerCard;
import cn.psvmc.cxzapi.response.Result;
import cn.psvmc.cxzapi.response.ResultGenerator;
import cn.psvmc.cxzapi.service.customer.TCustomerCardService;
import cn.psvmc.cxzapi.util.ToolUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 客户会员卡表相关操作
 *
 * @Author auto
 * @Date 2025-01-04
 */
@RestController
@RequestMapping("/mpapi/customer_card")
public class TCustomerCardController {

    @Resource
    private TCustomerCardService tCustomerCardService;

    /**
     * @Description 客户会员卡列表
     * @Date 2025/1/4 19:13
     * @Author YWX
     * @Param [request]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/list_card")
    public Result listCard(HttpServletRequest request) {
        int userid = request.getIntHeader(GlobalConstant.USRID);
        return ResultGenerator.genSuccessResult("查询成功", tCustomerCardService.listCard(userid));
    }

    /**
     * @Description 会员卡查询
     * @Date 2025/1/4 22:09
     * @Author YWX
     * @Param [request, card]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/detail")
    public Result detail(HttpServletRequest request, @RequestBody TCustomerCard card) {
        int userid = request.getIntHeader(GlobalConstant.USRID);
        String bizCardNo = card.getBizCardNo();
        ToolUtils.validation(new Object[]{bizCardNo, "支付宝业务卡号", 2});
        return ResultGenerator.genSuccessResult("查询成功", tCustomerCardService.detail(userid, bizCardNo));
    }

    /**
     * @Description 是否是会员
     * @Date 2025/1/4 22:20
     * @Author YWX
     * @Param [request, card]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/is_member")
    public Result isMember(HttpServletRequest request) {
        int userid = request.getIntHeader(GlobalConstant.USRID);
        return ResultGenerator.genSuccessResult("查询成功", tCustomerCardService.isMember(userid));
    }
}
